import { defineStore } from 'pinia';

export const useusrStore = defineStore('user', {
  state: () => ({
    token:null,
    userid:null,
    username:null,
    userinfo: [],
  }),
  actions: {
    setAtoken(token) {
      this.token = token;
    },
    setuserid(userid) {
      this.userid = userid;
    },
    setusername(username) {
      this.username = username;
    },
    setuserinfo(userinfo) {
      this.userinfo = userinfo;
    },
    setuserdetail(key,value) {
      this.userinfo[key] = value;
    },
    logout() {
      this.token=null;
      this.userid=null;
      this.username=null;
      this.userinfo= []
    },
  },
  persist: {
    enabled: true,  // 启用持久化
    strategies: [
      {
        key: 'usr',  // 设置 activetabindex 存储的 key
        storage: localStorage,     // 使用 localStorage 存储
        paths: ['token','userid','username','userinfo'],  
      },
    ]
  },
});
